package com.gitee.wsl.mathematics.vector.vec

import com.gitee.wsl.io.dataproxy.DataGet
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.vector.VectorD

open class Vec(
    override val proxy: DataGet<Double>
): VectorD<Vec>{
    constructor(list: List<Double> = emptyList()):this(list.asProxy())
    constructor(vararg list:Number):this(list.map { it.toDouble() })

    override val self
        get() = this

    override val squaredLength: Double get() = proxy.fold(zero) { acc, fl ->
                                                      acc + fl * fl
                                                   }

    override fun rem(other: Vec): Vec {
        require(proxy.size == other.proxy.size) { "Dot product requires that both vectors are the same length" }

        return create(proxy.mapIndexed { i: Int, d: Double -> d % other.proxy[i] })
    }

    override fun div(other: Vec): Vec {
        require(proxy.size == other.proxy.size) { "Dot product requires that both vectors are the same length" }

        return create(proxy.mapIndexed { i: Int, d: Double -> d / other.proxy[i] })
    }

    override fun times(other: Vec): Vec {
        require(proxy.size == other.proxy.size) { "Dot product requires that both vectors are the same length" }

        return create(proxy.mapIndexed { i: Int, d: Double -> d * other.proxy[i] })
    }


    override fun create(values: List<Double>) = Vec(list = values)

}